Replication materials for “Estimating Individuals' Political Perceptions While Adjusting for Differential Item Functioning” by Stephen A. Jessee (The University of Texas at Austin). Forthcoming, Political Analysis.

## NOTE: all files (including a folder structure that should not be modified) are in the “material.zip” file. Unzip this file and then follow the replication instructions below.

To properly function, this file must be run within the appropriate folder structure, as stored in the .zip file. Otherwise, users must adjust all paths for storing and loading files in the code accordingly. Note that these files use relative paths (e.g. “../figures/filename“) which may need to be changed depending on operating system. The code files below will write formatted data, output and figure files to the various directories (note that “figures” and “output” will be empty until these code files are run).

This code was run on an iMac with a 3.2 GHz Intel Core i5 processor and 8 GB of memory, using R 3.6.0 and JAGS 4.3.0. The code should take roughly one day to run on a relatively new computer, but may take more or less time depending on the machine. In particular, machines with low amounts of memory may run very slowly given the large number of unknown parameters in the models as well as the large number of iterations stored for the MCMC output. If you do not care about reproducing the paper’s results to a high degree of precision (e.g. to two decimal places for each parameter), you can run the code much faster by decreasing the number of iterations run for each of the two JAGS models (in BAM-Model_Running.R) as well as for the ideal point model (in IdealPoint_16CCES.R).

The code used below requires R as well as the following installed packages (version numbers are listed in parentheses after each package name): rjags (4-9), pscl (1.5.2), rio (0.5.16), car (3.0-3), boa (1.1.8-2), coda (0.19-3), mcmcplots(0.4.3), here (0.1)

Note that prior to installing the rjags package, you should install JAGS, which can be found here: http://mcmc-jags.sourceforge.net

To reproduce the paper’s results, run each of the following code files (with .R extensions) *IN THE ORDER LISTED BELOW*. These code files can be found in the “code” folder of the replication materials. See notes after each file summarizing what they do:

	CCES16_data_formatting.R
			this file takes raw CCES data and formats it into various
			objects for analysis by other code files
			these objects are saved to CCES16_UTB_Formatted.RData
			which is in the data folder

	BAM_Model_Running.R
			this file takes the formatted CCES data and estimates 
			the “Politician Anchors” and “Vignette Anchors” models
			using JAGS (called through the rjags package)
			outputs MCMC sims files: “/output/CCES16_Standard_BAM_zhatID.RData”
			and “/output/CCES16_Vignettes_BAM_Sims_zhatID.RData”
			which are reformatted and analyzed by subsequent code files
			the JAGS model is written separately in the file “BAM_JAGScode_zhatID.bug”

	BAM_Results_Processing.R
			takes MCMC output from BAM_Model_Running.R for  
			“Politician Anchors” and “Vignette Anchors” models
			and formats it to impose identifying restrictions,
			as well as adding variables to CCES16 data
			saving everything for analysis with later code files 
			in file: “/output/CCES16_Cand_and_Vig_Output_Processed.RData”

	IdealPoint_16CCES.R
			estimates policy-based ideal point model based on 
			respondents’ positions on binary policy items
			as well as politician and vignette stances on these items
			saves output in: file under “output” folder named
			ideal run resps, pols, and vignettes (100k burn 400k run thin 100).RData
			NOTE: this will take some time (maybe hours) to run
			if you just want to see the basics of output, with less precision,
			you can decrease the number of iterations run

	Table_and_Figure_Code.R
			this file takes the data and output from above and produces 
			the tables and figures in the main paper and appendix


After running the final code file (“Table and Figure Code.R”) you should PDF files for each article and appendix figure in the “figures” folder (note, Figure 1 in the article is an example of a survey question so is not included in the replication). This code file also will print summaries of each regression from the tables in the article and appendix.